package com.example.spider;

import cn.hutool.core.util.ReUtil;
import com.example.spider.config.RestTemplateConfiguration;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.Charset;
import java.util.List;

public class BmcxPageTester {

    private static RestTemplate rest = RestTemplateConfiguration.getInstance(Charset.forName("GBK"));

    private static void testNormalPage() {
        String url = "https://swgwsm.bmcx.com/jxcng8wt_10__swgwsmlist/";
        String result = rest.getForObject(url, String.class);
        String content = ReUtil.findAllGroup1("<ul class=\"list\">(.*?)</a></li></ul>", result).get(0);
        String regex = "<li><a href=\"(.*?)\" target=\"_blank\">(.*?)</a></li>";
        List<String> detailUrlList = ReUtil.findAll(regex, content, 1);
        List<String> titleList = ReUtil.findAll(regex, content, 2);
        System.out.println();
    }

    private static void testDetail() {
        String url = "https://swgwsm.bmcx.com/weishimegangjinhunningtu_loubanzaiy__xswgwsm/";
        String result = rest.getForObject(url, String.class);
        String content = ReUtil.findAllGroup1("<div class=\"neirong\">(.*?)</div>", result).get(0);

        String id = url.substring(url.lastIndexOf('/', url.lastIndexOf('.')));
        System.out.println(content);
    }

}
